package com.example.baiduapi.serviceListener.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.baiduapi.domain.AjaxResult;
import com.example.baiduapi.serviceListener.newListerner.config.ListenerConfig;
import com.example.baiduapi.serviceListener.old.service.OldMvcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/mvctest")
public class MVCController {
    @Autowired
    ListenerConfig listenerConfig;
    @Resource
    private OldMvcService oldmvcService;

    //    http://127.0.0.1:8888/mvctest/newmvc?beanName=MvcService1
    @GetMapping("/newmvc")
    @ResponseBody
    public AjaxResult newMvc(@RequestParam(value = "beanName",required = true) String beanName){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name","张三");
        jsonObject.put("age",18);
        jsonObject.put("sex","男");
        return listenerConfig.dispatchEvent(beanName,jsonObject);
    }

//    http://127.0.0.1:8888/mvctest/oldmvc?beanName=MvcService1
    @GetMapping("/oldmvc")
    @ResponseBody
    public AjaxResult oldMvc(@RequestParam(value = "beanName",required = true) String beanName){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name","张三");
        jsonObject.put("age",18);
        jsonObject.put("sex","男");
        return oldmvcService.versionSelector(beanName,jsonObject);
    }
}
